#include "Mob.h"
#include "Level.h"


Mob::Mob()
{

}

void Mob::init(const sf::Vector2f position, ImgMgr *imageManager)
{
    setPosition(position);
    m_currentRender = 0;
    m_rectHeart.setFillColor(sf::Color::Red);
}

void Mob::setPosition(const sf::Vector2f position)
{
    int e = 0;
    while(e < 8)
    {
        m_skin[e].setPosition(position);
        e++;
    }
}

void Mob::setDommage(const int dommage)
{
    m_heart -= dommage;
}

sf::Vector2f Mob::getPosition() const
{
    return m_skin[m_currentRender].getPosition();
}

void Mob::maj(Player *player, Level *level)
{
    if(m_heart <= 0)
        level->delMob(this);
}

void Mob::render(sf::RenderWindow *app)
{
    app->draw(m_skin[m_currentRender]);
    if(m_heart < m_maxHeart)
    {
        int heart = m_heart * 100 / m_maxHeart;
        m_rectHeart.setSize(sf::Vector2f(heart * m_skin[m_currentRender].getGlobalBounds().width / 100, 5));
        m_rectHeart.setPosition(m_skin[m_currentRender].getPosition().x, m_skin[m_currentRender].getPosition().y - m_rectHeart.getSize().y);
        app->draw(m_rectHeart);
    }
}
